package xyz.thoughtset.viewer.executor.blocks.executor;


import xyz.thoughtset.viewer.modules.step.entity.BlockTypeEnum;

import java.util.concurrent.ConcurrentHashMap;


public class ExecutorRegistry {
    private static AbstractBlockExecutor DEFAULT = null;
    private static final ConcurrentHashMap<BlockTypeEnum, AbstractBlockExecutor> Executor_Map = new ConcurrentHashMap<>();
//    @Getter
//    private static final LinkedHashSet<String> Executor_Keys = new LinkedHashSet<>();

    public static void register(BlockTypeEnum supportType,AbstractBlockExecutor executor) {
        Executor_Map.put(supportType, executor);
    }

    public static AbstractBlockExecutor findExecutor(String supportType){
        return findExecutor(BlockTypeEnum.fromType(supportType));
    }
    public static AbstractBlockExecutor findExecutor(BlockTypeEnum supportType){
        AbstractBlockExecutor executor = Executor_Map.get(supportType);
        if (executor == null) {
            return DEFAULT;
        }
        return executor;
    }
    public static AbstractBlockExecutor setDefault(AbstractBlockExecutor executor) {
        return DEFAULT=executor;
    }

}
